package ar.edu.unsam.algo3.plantasvszombies.homes

import ar.edu.unsam.algo3.plantasvszombies.dominio.Zombie
import org.uqbar.commons.model.CollectionBasedHome
import org.uqbar.commons.utils.Observable

@Observable
class HomeZombies extends CollectionBasedHome<Zombie> {

	new() {
		this.init
	}

	def void init() {
		this.create("Debilucho", 10, 10, "Zombie 10/10")
		this.create("Bailarin", 10, 70, "Zombie 10/70")
		this.create("Zombie con Armadura", 20, 70, "Zombie 20/70")
		this.create("Karateka", 10, 80, "Zombie 10/80")
		this.create("Karateka con Armadura", 30, 80, "Zombie 30/80")
		this.create("Soldado", 10, 90, "Zombie 10/90")
		this.create("Mutante", 30, 90, "Zombie 30/90")
	}

	def void create(String zNombre, Integer zAtaque, Integer zDefensa, String zDescripcion) {
		var zombie = new Zombie
		zombie.nombre = zNombre
		zombie.ataque = zAtaque
		zombie.defensa = zDefensa
		zombie.descripcion = zDescripcion
		this.create(zombie)
	}

	def buscar(String nombre) {
		allInstances.filter[Zombie|this.match(nombre, Zombie.getNombre)].toList
	}

	def mostrar() {

		//Devuelve toda la lista de zombies
		allInstances
	}

	def match(Object expectedValue, Object realValue) {
		if (expectedValue == null) {
			return true
		}
		if (realValue == null) {
			return false
		}
		realValue.toString().toLowerCase().contains(expectedValue.toString().toLowerCase())
	}

	override protected getCriterio(Zombie arg0) {
		null
	}

	override createExample() {
		null
	}

	override getEntityType() {
		typeof(Zombie)
	}

}
